package tpo.lmhprovider.lmhprovider.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dto.ShowWares;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.Album;
import pojo.Sort;
import pojo.Wares;
import tpo.lmhprovider.lmhprovider.dao.WaresMapper;
import tpo.lmhprovider.lmhprovider.service.WaresService;
import until.OrderCoderUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class WaresServiceImpl implements WaresService {
    @Autowired
    WaresMapper waresMapper;

    @Override
    public PageInfo getWares_Page(Map map) {
        PageHelper.startPage((Integer) map.get("pageNum"),(Integer) map.get("pageSize"));
        List list=waresMapper.getWares(map);
        PageInfo pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<ShowWares> getWares(Map map) {
        return waresMapper.getWares(map);
    }

    @Override
    public List<Wares> getWares2(Map map) {
        return waresMapper.getWares2(map);
    }

    @Override
    public List<Album> getAlbum(Map map) {
        return waresMapper.getAlbum(map);
    }

    @Override
    public int delAlbum(Map map) {
        return waresMapper.delAlbum(map);
    }

    @Override
    public int addAlbum(List<Album> list) {
        return waresMapper.addAlbum(list);
    }

    @Override
    @Transactional
    public int addWares(Wares wares, List<String> list) {
        Long st=Long.valueOf(OrderCoderUtil.getRandom((long)9));
        wares.setId(st);
        if (list!=null){
            wares.setLog(list.get(0));
            List<Album> lists=new ArrayList();
            for (String s :list){
                Album album=new Album();
                album.setWaresId(st);
                album.setName(s);
                lists.add(album);
            }
            waresMapper.addAlbum(lists);
        }
        waresMapper.addWares(wares);
        return 1;
    }

    @Override
    public int updateWares(Wares wares) {
        return waresMapper.updateWares(wares);
    }

    @Override
    public int delWares(Map map) {
        return waresMapper.delWares(map);
    }

    @Override
    public List<Sort> getSort(Map map) {
        return waresMapper.getSort(map);
    }

    @Override
    public int addSort(Sort sort) {
        return waresMapper.addSort(sort);
    }

    @Override
    public int updateSort(Sort sort) {
        return waresMapper.updateSort(sort);
    }

    @Override
    public int delSort(Map map) {
        return waresMapper.delSort(map);
    }

    @Override
    public PageInfo<ShowWares> getWaresList(Map map) {
        PageHelper.startPage((Integer) map.get("pageNum"),(Integer) map.get("pageSize"));
        List list=waresMapper.getWaresList(map);
        PageInfo pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public PageInfo<ShowWares> getWaresList2(Map map) {
        PageHelper.startPage((Integer) map.get("pageNum"),(Integer) map.get("pageSize"));
        List list=waresMapper.getWaresList2(map);
        PageInfo pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public PageInfo<ShowWares> getWaresList3(Map map) {
        PageHelper.startPage((Integer) map.get("pageNum"),(Integer) map.get("pageSize"));
        List list=waresMapper.getWaresList3(map);
        PageInfo pageInfo=new PageInfo(list);
        return pageInfo;
    }
}
